<template>
  <el-table
    :data="cailist"
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号"
      width="100">
    </el-table-column>
    <el-table-column
      prop="gname"
      label="商品名称"
      width="100">
    </el-table-column>
    <el-table-column
      prop="rnum"
      label="购买数量"
      width="100">
    </el-table-column>
    <el-table-column
      prop="rname"
      label="购买人"
      width="100">
    </el-table-column>
    <el-table-column
      prop="rtime"
      label="购买时间"
      width="100">
      <template slot-scope="scope">
          {{scope.row.rtime|datefmt("YYYY-MM-DD")}}
      </template>
    </el-table-column>
    <el-table-column
      prop="price"
      label="资金"
      width="100">
    </el-table-column>
      <el-table-column
        prop="status"
        label="状态"
        width="100">
        <template slot-scope="scope">
          {{scope.row.status|statusFit}}
        </template>
    </el-table-column>
    <el-table-column
      label="操作">
      <template slot-scope="scope">
        <el-button v-if="scope.row.status==0?!isShow:isShow" type="primary" icon="el-icon-edit" @click="updatestatus(scope.row)">审核</el-button>
        <el-button v-if="scope.row.status==0?isShow:!isShow" type="primary" icon="el-icon-edit" @click="updatestatus(scope.row)">反审核</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
    export default {
        name: "CaiList",
      data(){
          return{
            cai:{},
            cailist:[],
            isShow:false
          }
      },
      methods:{
        updatestatus:function(row){
          this.cai=row;
          if(row.status==0){
              this.cai.status=1;
          }else{
            this.cai.status=0;
          }
          this.$http.post("/cai/updatestatus",this.cai).then(
            (res)=>{
              if(res.data.success){
                this.$message({
                  message:res.data.message,
                  type: 'success',

                });
                this.cai={};
                this.search();
              }else{
                this.$message.error(res.data.message);
              }
            }
          );
        },
          search:function () {
              this.$http.get("/cai/cailist").then(
                (res)=>{
                  if(res.data.success){
                    this.cailist=res.data.result;
                  }else{
                    this.$message.error(res.data.message);
                  }
                }
              );

          }
      },
      filters:{
        statusFit:function (val) {
          var str="";
            if(val==0){
                str="未审核"
            }
            if(val==1){
              str="已转采购"
            }
            return str;
        }
      },
      mounted() {
          this.search();
      }
    }
</script>

<style scoped>

</style>
